local nuchi = fk.CreateSkill{
  name = "lingling__nuchi",
}

Fk:loadTranslationTable{
  ["lingling__nuchi"] = "怒叱",
  [":lingling__nuchi"] = "准备阶段，你可以视为使用一张【杀】，若造成伤害，其交给你一张牌，结束阶段其回复1点体力；若未造成伤害，其获得你一张牌。",

  ["#lingling__nuchi-invoke"] = "怒叱：你可以视为使用一张【杀】",
  ["#lingling__nuchi-give"] = "怒叱：请交给 %src 一张牌",
  ["#lingling__nuchi-prey"] = "怒叱：获得 %src 一张牌",
}

nuchi:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(nuchi.name) and player.phase == Player.Start and
      player:canUse(Fk:cloneCard("slash"), {bypass_times = true})
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "slash",
      skill_name = nuchi.name,
      prompt = "#lingling__nuchi-invoke",
      cancelable = true,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      },
      skip = true,
    })
    if use then
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).extra_data
    room:useCard(use)
    if use == nil or player.dead then return end
    for _, p in ipairs(use.tos) do
      if player.dead then return end
      if not p.dead then
        if use.damageDealt and use.damageDealt[p] then
          if not p:isNude() then
            room:addPlayerMark(p, "lingling__nuchi-turn", 1)
            local card = room:askToCards(p, {
              min_num = 1,
              max_num = 1,
              include_equip = true,
              skill_name = nuchi.name,
              prompt = "#lingling__nuchi-give:"..player.id,
              cancelable = false,
            })
            room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, nuchi.name, nil, false, p)
          end
        else
          if not player:isNude() then
            local card = room:askToChooseCard(p, {
              target = player,
              flag = "he",
              skill_name = nuchi.name,
              prompt = "#lingling__nuchi-prey:"..player.id,
            })
            room:moveCardTo(card, Card.PlayerHand, p, fk.ReasonPrey, nuchi.name, nil, false, p)
          end
        end
      end
    end
  end,
})

nuchi:addEffect(fk.EventPhaseStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("lingling__nuchi-turn") > 0 and target.phase == Player.Finish
  end,
  on_use = function (self, event, target, player, data)
    player.room:recover{
      who = player,
      num = player:getMark("lingling__nuchi-turn"),
      recoverBy = player,
      skillName = nuchi.name,
    }
  end,
})

return nuchi
